package com.fivefu.core.hik.controller;

import com.fivefu.base.common.utils.str.StrUtils;
import com.fivefu.base.web.controller.BaseController;
import com.fivefu.base.web.vo.ResultInfo;
import com.fivefu.core.hik.dto.response.CameraDetail;
import com.fivefu.core.hik.dto.response.CameraLonLatResp;
import com.fivefu.core.hik.services.DbHikCameraService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "监控点")
@RestController
@RequestMapping("/camera")
public class CameraController extends BaseController {
    private Logger logger = LoggerFactory.getLogger(CameraController.class);

    @Resource
    private DbHikCameraService dbHikCameraService;

    @RequestMapping(path = "/queryCameraLonLat",method = RequestMethod.POST)
    @ApiOperation(value = "获得监控点经纬度",httpMethod = "POST",response = ResultInfo.class,notes = "获得监控点经纬度")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cameraName", value = "监控点名称", paramType = "query",required = false, dataType = "String")
    })
    public ResultInfo queryCameraLonLat(){
        try {
            logger.info("获得监控点经纬度接收的参数："+ request.getParameter("cameraName"));
            String cameraName = StrUtils.isCheckNull(request.getParameter("cameraName"));
            List<CameraLonLatResp> cameraLonLat =  dbHikCameraService.queryCameraLonLat(cameraName);

            return ResultInfo.renderSuccess(cameraLonLat);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultInfo.renderError("获得监控点经纬度失败");
    }

    @RequestMapping(path = "/queryCameraDetail",method = RequestMethod.POST)
    @ApiOperation(value = "获得监控点详情",httpMethod = "POST",response = ResultInfo.class,notes = "获得监控点详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "监控点编号", paramType = "query",required = true, dataType = "int")
    })
    public ResultInfo queryCameraDetail(Integer id){
        try {
            logger.info("获得监控点详情接收的参数："+ id);
            //判断监控点是否为空
            if (id==null){
                return ResultInfo.renderError("监控点编号不能为空");
            }
            CameraDetail detail =  dbHikCameraService.queryCameraDetail(id);
            return ResultInfo.renderSuccess(detail);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultInfo.renderError("获得监控点详情失败");
    }
}
